<template>
<div>
  <div id="divPlugin" class="plugin"></div>
  <p style="color:red">{{showLoadingText}}</p>
</div>
</template>
<script>
export default {
    props:['vedioList','iRet'],
    data(){
      return{

        showLoadingText:'开始预览'
      }
    },
    watch:{
        vedioList(newVal,oldVal){
          var that=this
          console.log('newVal')
         console.log(newVal)
       if(that.iRet==0){
            that.initVedio()
        }else{
           that.iChannelID()
       }

        }
    },
    mounted(){
      var that=this
        // 检查插件是否已经安装过
    if (-1 == WebVideoCtrl.I_CheckPluginInstall()) {
      alert("请安装WebComponents.exe！");
      return;
      }

       if(that.iRet==0){
            that.initVedio()
        }else{
           that.iChannelID()
       }

    },
    methods:{
       initVedio(){
         console.log('登录')
           var that=this
                //第一步，初始化并嵌入插件
        WebVideoCtrl.I_InitPlugin('100%', '100%',{
          iWndowType: 1,
          cbInitPluginComplete: function () {
            WebVideoCtrl.I_InsertOBJECTPlugin("divPlugin");
          }
        })
        WebVideoCtrl.I_InsertOBJECTPlugin("divPlugin");
        WebVideoCtrl.I_ChangeWndNum(1)
               // 第二步，登录设备
              //  that.vedioList.ip, 1, that.vedioList.port, that.vedioList.userName, that.vedioList.passWord
       WebVideoCtrl.I_Login(that.vedioList.ip, 1, that.vedioList.port, that.vedioList.userName, that.vedioList.passWord,{
          success:function (){
           that.showLoadingText="登录成功"
            // WebVideoCtrl.I_GetAnalogChannelInfo(that.ip,{async: false})
            //第三步，播放画面
            let iRetPlay=WebVideoCtrl.I_StartRealPlay(that.vedioList.ip, {
              iStreamType:2,
              iChannelID:that.vedioList.channelNumber
            })
            if (0 == iRetPlay) {
              that.showLoadingText="预览成功"
            } else {
              that.showLoadingText="预览失败"
            }
          },error:function(){
            //  that.showLoadingText="登录失败"
          }
        })

       },
       iChannelID(){

        var that=this
       var oWndInfo = WebVideoCtrl.I_GetWindowStatus();
       if (oWndInfo != null) {// 已经在播放了，先停止
	        	WebVideoCtrl.I_Stop();
	         }
        let iRet=WebVideoCtrl.I_StartRealPlay(that.vedioList.ip, {
              iStreamType:2,
              iChannelID:that.vedioList.channelNumber
            })
            if (0 == iRet) {
              that.showLoadingText = "预览成功";
            } else {
              that.showLoadingText = "预览失败";
            }
      },
    }

}
</script>
<style scoped>
  .plugin{
      width:100%;
     height:650px;
     background:rgba(0,0,0,0.9);
      transition:normal!important;
  }
</style>
